<?php
/**
 * Created by PhpStorm.
 * User: wg
 * Date: 16/4/19
 * Time: 9:50
 */
namespace C\mod{
    use C\lib\Sql;
    use C\lib\Db;
    class orderPiece extends mod {

        protected static $__table_s = 'order_piece';
        protected static $__primary_s = 'id';

        // --- 获取发件所需要的金额 ---
        // --- 判断标准 ---
        // --- 城与城之间,以及重量 ---
        public static function getPrice($from, $to, $weight = 1) {

            // --- 现在城与城之间统一 20 块,重量只有 1 公斤 ---
            return 20;

        }

        public static function groupBy($workerId,$state,$stateIn,$parameter) {

            $list = [];
            $sql = new Sql();
            $sql->select($parameter.', id,sack_id, COUNT(0) AS count', static::$__table_s)->where(['worker_id' => $workerId, 'state' => $state, 'state_in' => $stateIn])->groupBy($parameter)->by('id','DESC')->limit(0,10);
            if ($ps = Db::query($sql->sql)) {
                $list = [];
                while ($o = $ps->fetchObject(static::class))
                    $list[] = $o;
            }
            return $list;

        }

        public static function search($orderIds, $sqlS, $sql,$lastId) {
            $count = count($sql);
            $sql = new Sql();
            if($count){
                $sql->select('*', static::$__table_s)->append(' WHERE id IN ('.$orderIds.') AND '.$sqlS.' AND '.$lastId)->by('id','DESC')->limit(0,10);
            }else{
                $sql->select('*', static::$__table_s)->append(' WHERE id IN ('.$orderIds.') AND '.$lastId)->by('id','DESC')->limit(0,10);
            }
            if ($ps = Db::query($sql->sql)) {
                $list = [];
                while ($o = $ps->fetchObject(static::class))
                    $list[] = $o;
                return $list;
            } else
                return false;
        }

    }

}

